// -----------------------------
// Author: 		Dhaenens Gert	
// Creation: 	11/6/2014 8:39:00 PM				
// -----------------------------

#include "TriangleOscillator.h"

TriangleOscillator::TriangleOscillator()
	: Oscillator(SoundWaveType::Triangle)
{
}

TriangleOscillator::~TriangleOscillator()
{
}

Float TriangleOscillator::Sample(Float t) const
{
	// Generate the Sawtooth Wave
	Float s = 0.0f;
	for (UInt32 h = 1; h <= Harmonics; ++h)
	{
		Float sh = Math::Sin(2.0f * Math::Pi * (Float)h * Frequency * t);
		sh /= (Float)h;
		s += sh;
	}
	s = ((Amplitude / 2.0f) - (Amplitude / Math::Pi)) * s;

	// Take the absolute value for the Triangle Wave
	s = Math::Abs(s);

	return s;
}